/**
 * 获取大驼峰写法
 * @param camelName
 * @returns {string}
 */
function getUpperCamelCaseName(camelName) {
  return camelName.slice(0, 1).toUpperCase() + camelName.slice(1)
}

/**
 * 根据驼峰获取连词写法
 * @param camelName
 * @returns {string}
 */
function getStrikeName(camelName) {
  const matchedList = camelName.match(/[A-Z]/g)
  return camelName
    .split(/[A-Z]/)
    .map((item, index) => (index === 0 ? item : matchedList[index - 1] + item))
    .join('-')
    .toLowerCase()
}

module.exports = {
  getUpperCamelCaseName,
  getStrikeName,
}

// function getStrikeName2(camelName) {
//   const matchedList = camelName.match(/[A-Z]/g)
//   let start = 0
//   let restStr = camelName
//   let result = []
//   const matchedIndexList = matchedList.map((item, index) => {
//     start = restStr.indexOf(item) + (index === 0 ? 0 : result[index - 1])
//     result.push(start + 1)
//     restStr = camelName.slice(start + 1)
//     return start
//   })
//   return (
//     matchedIndexList
//       .map((item, index) =>
//         index === 0 ? camelName.slice(0, item) : camelName.slice(matchedIndexList[index - 1], item),
//       )
//       .map((item) => item.toLowerCase())
//       .join('-') +
//     '-' +
//     camelName.slice(matchedIndexList[matchedIndexList.length - 1]).toLowerCase()
//   )
// }
